<template>
    <div class='commonEdit'  v-loading="loading" v-if="shows">

        <div class='commonList_title commonList_title_ytj' v-if="isYtj=='Y'&&isReturn=='Y'" >  <i class='el-icon-arrow-left' @click="returns" style='margin-right:10px;float:left;line-height:50px'>返回</i><i class='fa fa-info-circle'></i>{{title}}</div>
        <div class="commonEdit_content">
            <template v-if="tabJson.length>1&&typess">
                <funeral-title v-if="typess=='funeral_title'" :data="data" :exkey="exkeys"></funeral-title>
            </template>
            <template  v-for="(item,index) in tabJson"  >
                <div v-for="(card,index2) in item.list" :style="card.width" class="items cards">
                    <form-view ref="myFormss"  :cards="card" :appid="appid" :data="data" :params="params" :showForm="showForm" :sId="sId" @goSearch="goSearch" @goSeach2="goSeach2"  :selectData="selectData"  @openWinEdit="openWinEdit" @remove="remove" @changeInput="changeInput" @funeralItemSelectEvent="funeralItemSelectEvent"  :oldData="oldData"></form-view>
                                
                </div>
            </template>
        
        </div>
        <div class='btns2' >
           
                 <el-button type="danger" @click="closeWin">关闭</el-button>
        </div>
         <el-dialog
            width="90%"
            title="打印预览"
            :visible.sync="innerVisible"
            append-to-body>
             <common-print :printDatas="printData" style='height:85VH' v-if="isPrint=='N'" @goSearch="goSearch2"></common-print>
       
        </el-dialog>

        <el-dialog
            width="800px"
            class="signDialog"
            title="签字确认"
            :visible.sync="signDialog"
            append-to-body>
             
            <sign v-if="signDialog" :signKey="signKey" :signKey2="signKey2" :signUrl="signUrl" :data="data" style="height:500px" @closes="signClose"></sign>
        </el-dialog>
        <el-dialog
            width="800px"
            class="signDialogsd"
            title="签字确认"
            :visible.sync="signDialogsd"
            append-to-body>
             
            <signsd v-if="signDialogsd" :signKey="signKey" :signKey2="signKey2" :signUrl="signUrl" :data="data" style="height:500px" @closes="signClose"></signsd>
        </el-dialog>

        <el-dialog
            width="800px"
            class="pays"
            title="收费"
            :visible.sync="pays"
            append-to-body>
             
            <pay v-if="pays" style="height:500px" :sId="payId" :type="payType" @closes="payClose"></pay>
        </el-dialog>
        <common-print :printDatas="printData" style='height:10px;position:absolute;bottom:-10px;' @goSearch="goSearch2" v-if="isPrint=='Y'||isPrint=='A'"></common-print>
        <iframe :src="src" style='height:1px;position:absolute;bottom:-10px;'></iframe>

       
    </div>
</template>
<script>
import Vue  from 'vue'
import CommonList  from '../components/list/commonList.vue'
import MyForm  from '../components/edit/Form.vue'
import sign  from '../components/edit/sign.vue'
import signsd  from '../components/edit/signsd.vue'
import FormMain  from '../components/edit/FormMain.vue'
import FormView  from '../components/edit/FormView.vue'
import tableEdit  from '../components/edit/tableEdit.vue'
import tableEditButton  from '../components/edit/tableEditButton.vue'
import tableEdit2  from '../components/edit/tableEdit2.vue'
import TableForm  from '../components/edit/TableForm.vue'
import FuneralItemTable  from '../components/byg/FuneralItemTable.vue'
import FuneralTitle  from '../components/byg/FuneralTitle.vue'
import pay  from '../components/common/pay.vue'
import BatchFuneralItemTable  from '../components/gm/BatchFuneralItemTable.vue'
import OrderFood  from '../components/byg/OrderFood.vue'
import CommonPrint  from './common/print/CommonPrint.vue'
import CemeteryTomb  from './gm/CemeteryTomb.vue'

export default {
    name:"commonView",
    props:["commonEditData"],
    components: {
       FormMain,
       FormView,
       MyForm,
       tableEdit,
       tableEditButton,
       tableEdit2,
       CemeteryTomb,
       FuneralItemTable,
       OrderFood,
       TableForm,
       CommonList,
       CommonPrint,
       FuneralTitle,
       sign,
       signsd,
       BatchFuneralItemTable,
       pay,
    },
    provide: function () {
        return {
            prints: this.prints,
            saves:this.save,
            title:""
        }
    },
    data(){       
        return{
           
           isYtj:sessionStorage.getItem("isYtj"),
           shows:false,
           innerVisible:false,
           print_src:"",
           printData:{},
           printData2:{},
           tabJson:[],
           buttonJson:[],
           buttonJson2:[],
           buttonMsg:{},
           sKey:'',
           fieldPath:'',
           filename:'',
           isPrint:"N",
           url:'',
           sId:'',
           cId:'',
           pId:"",
           exId:"",//主表主键
           sn:'',
           data:{},
           selectData:{},
           saveList:"",
           oldData:{},
           showForm:false,
           loading:true,
           button:{},
           company:'',
           params:'',
           paramKey:'',
           exData:{},
           src:'',
           tabs:'',
           appid:'',
           mark:"",
           mark_monitor:"",
           mark_monitor_time:null,
           ids:"",//多选的id
           param_key:"",//额外的参数变量
           href:'',//当前页面完整的url,用于保存刷新的时候，返回给父界面
           saveIds:{},//保存后返回的主键ID
           first:'Y',
           loadParam:{},
           isSearch:"N",
           isApp:sessionStorage.getItem("isApp"),
           isRouter:'N',
           signDialog:false,
           signDialogsd:false,
           signKey:"",
           signKey2:"",
           signUrl:"",
           isReturn:"N",
           title:"",
           payId:"",
           pays:false,
           payType:"byg",
           mainStyle:{"position":"relative","width":"100%","flex":"1","display":"flex","height":"100%","flex-direction":"row","textAlign":"center"},
           typess:"",
           exkeys:""
        }
    },
    beforeRouteLeave(to, from, next){
       
        if(from.query.filename2=="殡仪馆系统/殡仪服务"){
            
            try{
                if(this.GLOBAL.dialogsImg)
                    this.GLOBAL.dialogsImg.get_actionType("closeSignal");
                this.GLOBAL.dialogsImg=null;
                this.GLOBAL.dialogs=null;
                this.GLOBAL.readId="";
                if(this.GLOBAL.socketsImg)
                    this.GLOBAL.socketsImg.close();
                if(this.GLOBAL.sockets)
                this.GLOBAL.sockets.close();
                
                this.GLOBAL.socketsImg=null;
                this.GLOBAL.sockets=null;
            }catch(e){}
        }
        next()
    },
    created(){
       
        const originalHeight=document.documentElement.clientHeight ||document.body.clientHeight;
        if(this.$route.query.isReturn){
            this.isReturn=this.$route.query.isReturn;
        }
       
        this.sKey=this.$route.query.sKey;
        this.fieldPath=this.$route.query.fieldPath;
        this.filename=this.$route.query.filename2;
        this.sId=this.$route.query.sId;
        if(this.$route.query.sSn){
            this.sn=this.$route.query.sSn;
        }
        if(this.$route.query.cId){
            this.cId=this.$route.query.cId;
        }
         if(this.$route.query.isRouter){
            this.isRouter=this.$route.query.isRouter;
        }
        if(this.$route.query.title){
            this.title=this.$route.query.isRoutitleter;
        }
        if(this.$route.query.title){
            this.title=this.$route.query.title;
        }
        let isCopy=this.$route.query.isCopy;

        if(this.$route.query.param_key){
            this.param_key=this.$route.query.param_key;
        }
        if(isCopy=='Y'){
            this.cId=this.sId;
            this.sId="";
        }
        this.company=this.$route.query.company;
        if(this.$route.query.appid){
            this.appid=this.$route.query.appid;
        }
         
        if(this.$route.query.params){
            this.params=this.$route.query.params;//目前用于殡仪服务项目区分是哪个部门选择的，从cs_winUrl直接传参
        }
         if(this.$route.query.paramKey){
            this.paramKey=this.$route.query.paramKey;
        }
        this.href = window.location.href; /* 获取完整URL */
        if(this.commonEditData){
            if(this.commonEditData.fieldPath){
                this.fieldPath=this.commonEditData.fieldPath;
            }
            if(this.commonEditData.isSearch){
                this.isSearch=this.commonEditData.isSearch;
            }
            if(this.commonEditData.filename2){
                this.filename=this.commonEditData.filename2;
            }
            if(this.commonEditData.sId){
                this.sId=this.commonEditData.sId;
            }else{
                this.sId="";
            }
            if(this.commonEditData.pId){
                this.pId=this.commonEditData.pId;
            }
            if(this.commonEditData.appid){
                this.appid=this.commonEditData.appid;
            }
            if(this.commonEditData.param_key){
                this.paramKey=this.commonEditData.param_key;
            }
            if(this.commonEditData.exData){
                this.exData=this.commonEditData.exData;
                delete this.commonEditData.exData; 
            }
            if(this.commonEditData.exId){
                this.exId=this.commonEditData.exId;
            }
            if(this.commonEditData.isYtj){
                this.isYtj=this.commonEditData.isYtj;
            }
            if(this.commonEditData.ids){
                this.ids=this.commonEditData.ids;
            }
            if(this.commonEditData.paramVals){//额外的参数
                this.params=this.commonEditData.paramVals;
            }
            if(this.commonEditData.sSn){//额外的参数
                this.sn=this.commonEditData.sSn;
            }
        }
        this.loadData();
        window.onresize = ()=>{
            return(()=>{
                        //键盘弹起与隐藏都会引起窗口的高度发生变化
            const resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
            console.log("heihgt====="+resizeHeight);
            if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') {
            window.setTimeout(function () {
                document.activeElement.scrollIntoViewIfNeeded()
            }, 0)
            }

            if(resizeHeight-0<originalHeight-0){
            //当软键盘弹起，在此处操作
                console.log("进入到软键盘弹起=========");
                //alert("进入到软键盘弹起=========")
                document.querySelector('body').setAttribute('style', 'height:'+originalHeight+'px;');
                this.scrollerHeight=resizeHeight;
                
            }else{
                //当软键盘收起，在此处操作
                console.log("进入到软键盘收起=========");
                document.querySelector('body').setAttribute('style', 'height:100%;');
                this.scrollerHeight="100%";
                
            }
            })()
                
        }
        
    },
    mounted(){
        console.log("1111111111111111111111111111111111111111111111111111111111")
        window.setTimeout(()=>{
            let els=document.getElementsByClassName("el-card__header");
            for(let i=0;i<els.length;i++){
                els[i].style.borderTop="2px solid #66b1ff"
            }
           
            
        },1000)
        
    },
     computed:{
        sIds:function(){
          return this.data["sId"]
        }
    },
    watch:{
         sIds:{
            handler: function (newVal) {
                console.log("watch-------sIds===========")
                if(this.first!='Y'){
                    this.sId=this.data.sId;
                   
                    this.loadDatas(true)
                    this.first='N'
                }
                 this.first='N'
            }
          }
       /* commonEditData:{
            handler: function (newVal) {
                console.log("11111111111111111111111111111")
                if(this.commonEditData){
                    if(this.commonEditData.fieldPath){
                        this.fieldPath=this.commonEditData.fieldPath;
                    }
                
                    if(this.commonEditData.filename2){
                        this.filename=this.commonEditData.filename2;
                    }
                    if(this.commonEditData.sId){
                        this.sId=this.commonEditData.sId;
                    }
                    if(this.commonEditData.appid){
                        this.appid=this.commonEditData.appid;
                    }
                    if(this.commonEditData.param_key){
                        this.param_key=this.commonEditData.param_key;
                    }
                }
                console.log("ddddddddddddddddddddddddddddddddddddddddd");
                // console.log("data===================================================")
                this.loadData()
            },      
            deep: true    //深度监听
        }*/
    },
    updated(){
    },
    methods:{
        returns(){
                //alert(2)
                this.$router.go(-1)
               // window.location.href="/#"+sessionStorage.getItem("path")
               //location.reload();
               ///history.back();
               //alert(sessionStorage.getItem("path"));
                 //this.$router.push({path:sessionStorage.getItem("path")});
            },
        closes(){
            clearInterval(this.mark_monitor_time)
        },
        openWinEdit(data){
            this.$emit("openWinEdit",data);
        },
        remove(data){
            let datas=JSON.parse(data);
            let pre=datas.pre;
            let exdata=datas.exdata;
            this.data[pre].splice(exdata,1);
        },
        loadData(){
            this.shows=false;
            let sef=this;
            let data={};
            data.sKey2=this.sKey;
            data.fieldPath=escape(this.fieldPath);
            data.filename=escape(this.filename);
            data.sId=this.sId;
               
            this.$post("business",'api/view/commonEditView',data).then(data=>{
                try{
                    if(data.status=='-ERR'){
                        this.$message.error(unescape(data.msg));
                         let item_={};
                        item_.type="close";
                        if(this.commonEditData){
                            item_.closeType="dialog";
                        }
                        this.$emit("closeWin",JSON.stringify(item_));
                        return;
                    }
                }catch(e){}
                
                let groups=data.group;
                let tabJson=[];
                tabJson=JSON.parse(JSON.stringify(data.tabFields));
               
                this.tabs=tabJson[0].tabName;
                sef.buttonJson=[];
                let buttons=data.buttonFields;
                for(let i=0;i<buttons.length;i++){
                    let group=buttons[i].group;
                    let isOk=true;
                    if(group){
                        group="{"+group.replace(/'/g,"\"")+"}";
                        //group="{\"noPre\":\"引导员录单\"}"
                        group=JSON.parse(group);
                        if(group.noPre){
                            if(groups==group.noPre){
                                isOk=false;
                            }
                        }
                        if(group.pre){
                            if(groups!=group.pre){
                                isOk=false;
                            }
                        }
                    }
                    if(isOk)
                    sef.buttonJson.push(buttons[i]);
                    
                }
               // sef.buttonJson=data.buttonFields;
                sef.buttonJson2=sef.buttonJson;
                

                sef.url=data.url;
                if(data.mark_monitor){
                    sef.mark_monitor=data.mark_monitor;
                    this.mark_monitor_time=window.setInterval(function(){
                        if(sef.GLOBAL.mark[sef.mark]=="Y"){
                            sef.GLOBAL.mark[sef.mark]="N";
                            try{
                                sef.loadDatas(false);
                        
                            }catch(e){}
                        }
                    },1000)
                }else{
                    sef.mark_monitor="";
                }
                if(data.mark){
                    sef.mark=data.mark;
                }else{
                    sef.mark="";
                }
                let child=[];
                let preId="";

                for(let i=0;i<tabJson.length;i++){
                    preId="";
                    child=[];
                    let lists=[];
                    let list=tabJson[i].list;
                    for(let j=0;j<list.length;j++){
                        let id=list[j].id;
                        if(id){
                            if(preId==""){
                                child.push(list[j]);
                                preId=id;
                            }else if(preId==id){
                                child.push(list[j]);
                            }else if(preId!=""&&preId!=id){
                                
                                let list_={};
                                list_.type="child"
                                list_.width="width:98%";
                                list_.list=[];
                                list_.child=JSON.parse(JSON.stringify(child));
                                let mainStyle=JSON.parse(JSON.stringify(this.mainStyle));
                                list_.mainStyle=mainStyle;
                                try{
                                    console.log(list[j],"list_.exkey======ss==")
                                    console.log(list[j].exkey,"list_.exkey======ss==")
                                    if(child[0].exkey&&child[0].exkey.flexs){
                                        list_.flex=child[0].exkey.flexs
                                        if(child[0].exkey.mainStyles){
                                            let styles=child[0].exkey.mainStyles;
                                            for(let key in styles){
                                                list_.mainStyle[key]=styles[key]
                                            }
                                        }
                                    }else if(list[j].exkey&&list[j].exkey.flexs){
                                        list_.flex=list[j].exkey.flexs
                                        if(list[j].exkey.mainStyles){
                                            let styles=list[j].exkey.mainStyles;
                                            for(let key in styles){
                                                list_.mainStyle[key]=styles[key]
                                            }
                                        }
                                    }
                                }catch(e){}
                                lists.push(list_)
                                preId=id;

                                child=[];
                                child.push(list[j])
                                console.log(list_,"lists---")
                            }
                        }else{
                            if(child.length!=0){
                                let list_={};
                                list_.type="child"
                                list_.width="width:98%";
                                list_.list=[];
                                list_.child=JSON.parse(JSON.stringify(child));
                                let mainStyle=JSON.parse(JSON.stringify(this.mainStyle));
                                list_.mainStyle=mainStyle;
                                try{
                                    if(child[0].exkey&&child[0].exkey.flexs){
                                        list_.flex=child[0].exkey.flexs
                                        if(child[0].exkey.mainStyles){
                                            let styles=child[0].exkey.mainStyles;
                                            for(let key in styles){
                                                list_.mainStyle[key]=styles[key]
                                            }
                                        }
                                    }
                                }catch(e){}
                                lists.push(list_)
                                 child=[];
                            }
                            lists.push(list[j]);
                        }
                    }
                    if(child.length!=0){
                        let list_={};
                        list_.type="child"
                        list_.width="width:98%";
                        list_.list=[];
                        list_.child=JSON.parse(JSON.stringify(child));
                        let mainStyle=JSON.parse(JSON.stringify(this.mainStyle));
                        list_.mainStyle=mainStyle;
                        try{
                            if(child[0].exkey&&child[0].exkey.flexs){
                                list_.flex=child[0].exkey.flexs
                                if(child[0].exkey.mainStyles){
                                    let styles=child[0].exkey.mainStyles;
                                    for(let key in styles){
                                        list_.mainStyle[key]=styles[key]
                                    }
                                }
                                
                            }
                        }catch(e){}
                        lists.push(list_)
                    }

                    tabJson[i].list=lists;
                    
                }
                console.log(tabJson,"tabJson=ss==s=s=s=s=s===")
                this.tabJson=tabJson;

                //console.log(this.tabJson[0].list[0].child[0].list[0].type,"created==s=s=s==")
                for(let i=0;i<this.tabJson.length;i++){
                    if(this.tabJson[i].list.length==1){
                        this.tabJson[i].list[0].width=this.tabJson[i].list[0].width+";height:100%;";
                        
                        this.tabJson[i].list[0].height="height:98%;display:flex;flex-direction:column;";
                    }

                    
                    
                }
                try{
                    if(this.tabJson.length>1){
                        this.typess=tabJson[0].list[0].child[0].list[0].type
                        this.exkeys=tabJson[0].list[0].child[0].list[0].exkey
                    }
                }catch(e){}
                sef.shows=true;
                try{
                    sef.loadDatas(false);
               
                }catch(e){}
                 window.setTimeout(function(){
                     try{
                         
                        let el=document.getElementsByClassName("el-tabs__content");
                        for(let i=0;i<el.length;i++){
                            el[i].style.flex="1";
                           // el[i].style.overflow="auto";
                            el[i].style.paddingBottom="10px";
                        }
                        let el2=document.getElementsByClassName("sn");
                        el2[0].parentNode.style.position="absolute";
                        el2[0].parentNode.style.bottom="-10";
                        el2[0].parentNode.style.left="0";

                       
                     }catch(e){}
                   
                     
                    if(sef.isYtj=="Y"){
                        document.getElementsByClassName("btns")[0].style.border="0";
                        document.getElementsByClassName("btns_wrap")[0].style.background="0";
                    }
                },1000)
                
            });
        },
        goSearch2(){
            let data_={};
            data_.type="goSearch";
            data_.searchType="dialog";
            data_.isSearch="Y";
            //parent.postMessage(JSON.stringify(data_),'*');
            this.$emit("goSearch",JSON.stringify(data_))
        },
        loadDatas3(){
            
            let el=this.$refs.myFormss;
            for(let i=0;i<el.length;i++){
                try{
                    el[i].goSearchList();
                }catch(e){}
                
            }
        },
        loadDatas2(){
            this.sId="";
            this.loadDatas(true);
            this.sn="";
        },
        loadDataParam(data){
            
            let paramKey=data.paramKey;
            let id=data.id;
            let params=data.params;


            console.log(data,"loadDataParam=========================")
            console.log(this.paramKey,"paramKey=========================")
            console.log(paramKey,"paramKey2=========================")
            console.log(this.commonEditData.params[paramKey],"loadDataParam=========================")
            if(params&&(!this.paramKey||((","+this.paramKey+",").indexOf(","+paramKey+",")==-1||this.commonEditData.params[paramKey]!=params))){
                this.paramKey=this.paramKey=="" ? paramKey:this.paramKey+","+paramKey;
                if(!this.commonEditData.params){
                    this.commonEditData.params={};
                }
                this.commonEditData.params[paramKey]=params;
                
                if(!this.commonEditData.defaultVal){
                    this.commonEditData.defaultVal={}
                }
                this.commonEditData.defaultVal[id]=params;
                if(data.exParams){
                    if(!this.exData){
                        this.exData={}
                    }
                    for(let key in data.exParams){
                        console.log("key===="+key)
                        this.exData[key]=data.exParams[key];
                    }
                    
                }
                /*console.log(this.commonEditData,"====")
                console.log(this.exData)
                console.log(data.exParams)*/
                this.loadDatas(true);
               
            }
            
            
        },
        loadDatas(isSet){
            console.log("loadDatas================================")
            this.loadParam={};
            this.loading=true;
            let sef=this;
            let data_={};
            data_.sId=sef.sId;
            data_.pId=sef.pId;
            data_.cId=sef.cId;
            data_.company=sef.company;
            data_.sSn=sef.sn;
            data_.ids=sef.ids;
            if(this.paramKey){
                //alert(this.paramKey)
                if(this.commonEditData){
                    let paramKeys=this.paramKey.split(",");
                    let params=this.commonEditData.params;
                    console.log(params,"params=============ss=s==")
                    if(paramKeys){
                        for(let i=0;i<paramKeys.length;i++){
                            let key=paramKeys[i];
                            data_[key]=params[key];
                            this.loadParam[key]=params[key];
                        }
                    }
                    
                    
                }else{
                
                    let paramKeys=this.paramKey.split(",");
                    for(let i=0;i<paramKeys.length;i++){
                        let key=paramKeys[i];
                        data_[key]=this.$route.query[key];
                        this.loadParam[key]=this.$route.query[key];
                    }
                    
                }
            }
            data_["filename2"]=this.filename;

            //按钮额外的参数，在cs_winButton表中wb_key和wb_params两个字段决定
            if(this.param_key){
                let params=this.param_key.split(",");
                for(let i=0;i<params.length;i++){
                    let val=this.$route.query[params[i]];
                    data_[params[i]]=escape(val);
                    this.loadParam[params[i]]=escape(val);
                }
            }
             for(let key in this.saveIds){
                
                data_[key]=this.saveIds[key];
            }
            //值的内容为{该表的字段名:值}
            data_["exData"]=JSON.stringify(this.exData);//设置额外的值，该值主要是给读取数据的后台赋一个默认值，比如是子表的外键，是选择行然后点新增，修改的时候，把选择的主表主键带到后台
            data_["exId"]=this.exId;//主表主键，然后在通用编辑界面可以用select * from 主表 where 主键=exId
            let urls=sef.url.split(",");
            let url=urls[0];
            if(urls.length>1){
                let urls_=urls[1].split("#");
                let appid_=urls_[0].replace("appid=","");
                let url_=urls_[1];
                sef.$post(appid_,url_,data_).then(json=>{
                    if(json.status=="+OK"){
                        sef.loadDataDetail(url,data_)
                    }else{
                        alert(unescape(json.msg))
                         this.closeWin();
                    }
                })
            }else{
                this.loadDataDetail(url,data_)
            }
            
        },
        loadDataDetail(url,data_,exData){
            let sef=this;
            sef.$post(this.appid,url,data_).then(data=>{
               // console.log(JSON.stringify(data),"datasss")
                try{
                  
                    for(let key in data[0].data){
                        //console.log("key1==="+key)
                        this.$set(this.data,key,data[0].data[key])
                    }
                    console.log("this.commonEditDefualt=================")
                    try{
                        if(this.commonEditData.defaultVal){
                            for(let key in this.commonEditData.defaultVal){
                                let ids=key.split(".");
                                this.$set(this.data[ids[0]],ids[1],this.commonEditData.defaultVal[key])
                            }   
                        }
                    }catch(e){}
                    
                    //主要用于不保存的数据，再次打开编辑界面的时候传值，像公墓批量购买，修改购买人信息
                    if(sessionStorage.getItem("commonEdit")){
                        this.$set(this.data,sessionStorage.getItem("commonEditField"),JSON.parse(sessionStorage.getItem("commonEdit")));
                        sessionStorage.setItem("commonEdit","")
                    }
                    if(this.first=='Y')
                        this.$set(this.data,"sId",this.sId)
                   // sef.data=data[0].data;
                    //console.log(this.data)
                    sef.saveList=data[0].saveList;
                    sef.oldData=JSON.parse(JSON.stringify(data[0].data));
                    sef.selectData=data[0].selectData;
                    sef.buttonMsg=data[0].buttonMsg;
                    /*if(isSet){
                        let forms=this.$refs.myForms;
                        for(let i=0;i<forms.length;i++){
                            let message=forms[i].setData(sef.data);
                           
                        }
                    }*/
                    if(data[0].field){
                        let fields= data[0].field;
                        for(let i=0;i<this.tabJson.length;i++){
                            for(let j=0;j<this.tabJson[i].list.length;j++){
                                for(let h=0;h<this.tabJson[i].list[j].list.length;h++){
                                    let id=this.tabJson[i].list[j].list[h].id;
                                    if(fields[id]=='N'){
                                        this.tabJson[i].list[j].list[h].isReadOnly='Y'
                                    }
                                }
                            }
                        }
                    }
                    if(data[0].dataSelectField){
                        let fields= data[0].dataSelectField;
                        for(let i=0;i<this.tabJson.length;i++){
                            for(let j=0;j<this.tabJson[i].list.lengtgh;j++){
                                for(let h=0;h<this.tabJson[i].list[j].list.length;h++){
                                    let id=this.tabJson[i].list[j].list[h].id;
                                    if(fields[id]){
                                        this.tabJson[i].list[j].list[h].dataSource=fields[id]
                                    }
                                }
                            }
                        }
                    }
                    if(data[0].button||data[0].data.button){
                        if(data[0].button)
                            sef.button=data[0].button;
                        else
                            sef.button=data[0].data.button
                        let buttons=[];
                        for(let i=0;i<sef.buttonJson2.length;i++){
                            let id=sef.buttonJson2[i].id;
                            if(sef.button[id]){
                                if(sef.button[id]!='N'){
                                    buttons.push(sef.buttonJson2[i])
                                }
                            }else{
                                
                                buttons.push(sef.buttonJson2[i])
                            }
                        }
                        sef.buttonJson=buttons;
                    }
                    
                    sef.showForm=true;
                    sef.loading=false;
                }catch(e){

                }

                window.setTimeout(function(){
                     let isBr="N";
                    let height="";
                    let els2=document.getElementsByClassName("cards");
                    for(let i=0;i<els2.length;i++){
                        let width=Number(els2[i].style.width.replace("%",""));
                        if(width<90&&isBr=='N'){
                            isBr="Y";
                            height=els2[i].clientHeight;
                        }else if(width<90&&isBr=='Y'){
                            let height_=els2[i].clientHeight;
                            if(height>0&&height_>0){
                                if(height>height_){
                                    els2[i].style.height=height+'px';
                                    els2[i].children[0].style.height=(height-8)+'px'
                                    //els2[i].children[0].style.height=(height)+'px'
                            
                                }else{
                                    els2[i-1].style.height=height_+'px';
                                    els2[i-1].children[0].style.height=(height_-8)+'px'
                                    //els2[i-1].children[0].style.height=(height_)+'px'
                                }
                            }
                           
                            isBr='N'
                            
                        }
                    }
                },1000)
                let that=this;
                that.$nextTick(() => {
                    let formss=that.$refs.myFormss;
                    for(let i=0;i<formss.length;i++){
                        try{
                            formss[i].initData();
                        }catch(e){}
                        
                        
                    }
                });
                
                
            })
        },
        initData(){
          
        },
        changeInput(data){
            let datas=JSON.parse(data);
            let id=datas.id;
            let pre=datas.pre;
            let val=datas.val;
            let exdata=datas.exdata;
            //console.log("pre==============="+pre+"=="+id+"="+val);
           // console.log(this.data)
            try{
                 //用于表格多条数据，不确定有多少条数据
                if(exdata||exdata=='0'){
                /* let num=Number(exdata);
                    let data_={};
                    
                    if(this.data[pre].length<num){
                        data_[id]=val;
                        this.data[pre].push(data_);
                    }else*/
                    this.data[pre][exdata]=JSON.parse(val);
                }else if(datas.index!=undefined&&datas.index!=""){//增对多条数据，但能知道有多少条
                   
                    let index=datas.index;//用于行号
                    this.data[pre][index][id]=val;
                }else{//普通input
                    this.data[pre][id]=val;
                }
            }catch(e){

            }
           
            
        },
        funeralItemSelectEvent(data){
          
            let forms=this.$refs.myFormss;
            console.log(forms,"forms====================")
            for(let i=0;i<forms.length;i++){
                try{
                    //forms[i].addItem2(data);
                    forms[i].addItem(data);
                }catch(e){}
            }
            /*if(this.$refs.tableEdits)
                this.$refs.tableEdits[this.$refs.tableEdits.length-1].addItem(data);*/
        },
        getScrollTop(){
           return  this.$refs.tableEdits[0].getScrollTop();
        },
        
        prints(name,val,isPrint){
            let printData_={};
            printData_.printName=name;
            printData_.sCurItem=val;
            printData_.appid=this.appid;
            printData_.token=sessionStorage.getItem("token");
            printData_.isPrint=isPrint;
            printData_.isSearch="Y"
            if(isPrint=="Y"){
                this.isPrint="Y";
            }else if(isPrint=="A"){
                this.isPrint="A";
            }else{
                this.isPrint="N";
                this.innerVisible=true;
                    //this.$emit("openWin",JSON.stringify(items))
            }
            this.printData=printData_;


        },
        btnClick(item){
           console.log(item,"items===============")
            let url=item.url;
            let type=item.type;
            let msg=item.msg;
           // console.log(item,"item=============================")
            if(type=="sign"){
                this.signKey=item.printKey;
                this.signKey2=msg;
                this.signUrl=url;
                this.signDialog=true;
            }if(type=="signsd"){
                this.signKey=item.printKey;
                this.signKey2=msg;
                this.signUrl=url;
                this.signDialogsd=true;
            }else if(type=="save"||type=='checkout'){
                let id=item.id;
                
                if(!msg)
                    this.save(item);
                
                else{
                   
                    if(this.buttonMsg[id]&&this.buttonMsg[id]=="Y"){
                        this.$confirm(msg, '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                            }).then(() => {
                                this.save(item);
                            }).catch(() => {
                                    
                        });
                    }else{
                        
                        this.save(item);
                    }
                    
                }
            }else if(type=="close"){
                if(this.GLOBAL.isChange){
                    this.$confirm('确定要关闭该界面?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.GLOBAL.isChange=false;
                        /*let item_={};
                        item_.type="close";
                        if(this.commonEditData){
                            item_.closeType="dialog";
                        }
                        this.$emit("closeWin",JSON.stringify(item_));*/
                        this.closeWin();
                    }).catch(() => {
                        
                    });
                }else{
                    /*let item_={};
                    item_.type="close";
                    if(this.commonEditData){
                        item_.closeType="dialog";
                    }
                    this.$emit("closeWin",JSON.stringify(item_));*/
                     this.closeWin();
                }
               
                
                //parent.postMessage(JSON.stringify(item_),'*');
            }else if(type=="printViewMenu"){
                let key=item.printKey.split(".");
                let vals="";
                if(key.length>1){
                    vals=this.data[key[0]][key[1]];
                }else if(key[0]=="ids"){
                    vals=this.ids;
                }else
                    vals=this.data[key[0]]

               
               /* if(item.url){
                    let items={};
                    items.buttonName="打印"+item.url;
                    items.text="打印"+item.url;
                    items.url="/commonPrint?printName="+item.url+"&sCurItem="+vals+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid;
                    this.$emit("openWin",JSON.stringify(items))
                    
                   
                    //parent.postMessage(JSON.stringify(items),'*');
                }else{*/
                    
                    let names=item.name.split("#");
                    let isPrint=names.length>1 ? names[1]:"";
                    let items={};
                    let name_=names[0];
                    name_=name_.replace("打印","");
                    items.buttonName="打印"+name_;
                    items.text="打印"+name_;
                    
                    items.url="/commonPrint?printName="+name_+"&printId="+this.data.printId+"&sCurItem="+vals+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid+"&isPrint="+isPrint;
                   // alert(items.url)
                   // parent.postMessage(JSON.stringify(items),'*');
                    let printData_={};
                    printData_.printName=name_;
                    printData_.sCurItem=vals;
                    printData_.printId=this.data.printId;
                    printData_.appid=this.appid;
                    printData_.token=sessionStorage.getItem("token");
                    printData_.isPrint=isPrint;
                    if(isPrint=="Y"){
                        this.isPrint="Y";
                    }else if(isPrint=="A"){
                        this.isPrint="A";
                    }else{
                        this.isPrint="N";
                        this.innerVisible=true;
                         //this.$emit("openWin",JSON.stringify(items))
                    }
                    
                    this.printData=printData_;
                    
                       
              //  }
               
            }else if(type=="printMenu"){
                let key=item.printKey.split(".");
                let vals="";
                if(key.length>1){
                    vals=this.data[key[0]][key[1]];
                }else
                    vals=this.data[key[0]]
                
                if(item.url){
                    this.src=''
                    var timestamp = (new Date()).getTime()/1000;
                    this.src="/commonPrint?printName="+item.url+"&printId="+this.data.printId+"&sCurItem="+vals+"&isPrint=Y&timestamp="+timestamp+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid;
                }else{
                    this.src=''
                    var timestamp = (new Date()).getTime()/1000;
                    this.src="/commonPrint?printName="+item.name+"&printId="+this.data.printId+"&sCurItem="+vals+"&isPrint=Y&timestamp="+timestamp+"&token="+sessionStorages.getItem("token")+"&appid="+this.appid;
                }
                
                
            }else if(type=="openWin"||type=="openWinEdit"){
                if(this.sId==""){
                     this.$message.error('请先保存数据');
                     return;
                }
                let id=item.id;
                let isOk=false;
                if(this.buttonMsg[id]&&this.buttonMsg[id]=="Y"&&item.msg){
                    isOk=true;
                }
                let sIds="";
                if(item.printKey){
                    let key=item.printKey.split(".");
                    if(key.length==2){
                        sIds=this.data[key[0]][key[1]]
                    }
                }
                //alert(sIds)
                if(isOk){
                    this.$confirm(item.msg, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        let items={};
                        items.buttonName=item.name;
                        items.text=item.name;
                        let url=item.url;
                        url=url.replace("#ids#",this.sId);
                        url=url.replace("#printId#",sIds);
                        for(let key in this.saveIds){
                            url=url.replace("#"+key+"#",this.saveIds[key]);
                        }

                        url=url+"&appid="+this.appid;
                        items.url=url;
                        var searchParams = this.queryURLparams(url);
                        items.appid=this.appid;
                        items.model=searchParams.model;
                        items.filename2=searchParams.filename2;
                        items.key=searchParams.key;;
                        items.sId=searchParams.sId;
                        items.width=searchParams.width;
                        items.height="height:"+searchParams.height;
                        items.fieldPath=searchParams.fieldPath;

                        if(type=="openWin")
                            this.$emit("openWin",JSON.stringify(items))
                        else
                            this.$emit("openWinEdit",JSON.stringify(items))
                    }).catch(() => {
                        
                    });
                }else{
                    let items={};
                    items.buttonName=item.name;
                    items.title=item.name;
                    items.text=item.name;
                    let url=item.url;
                    url=url.replace("#ids#",this.sId);
                    url=url.replace("#printId#",sIds);
                    for(let key in this.saveIds){
                        url=url.replace("#"+key+"#",this.saveIds[key]);
                    }
                    url=url+"&appid="+this.appid;
                    items.url=url;
                    var searchParams = this.queryURLparams(url);
                    items.appid=this.appid;
                    items.model=searchParams.model;
                    items.filename2=searchParams.filename2;
                    items.key=searchParams.key;;
                    items.sId=searchParams.sId;
                    items.exId=searchParams.exId;
                    items.fieldPath=searchParams.fieldPath;
                    items.width=searchParams.width;
                    items.height="height:"+searchParams.height;
                    
                    if(type=="openWin")
                        this.$emit("openWin",JSON.stringify(items))
                    else
                        this.$emit("openWinEdit",JSON.stringify(items))
                }
                

            }
        },
        queryURLparams(url) {
            let obj = {}
            if (url.indexOf('?') < 0) return obj
            let arr = url.split('?')
            url = arr[1]
            let array = url.split('&')
            for (let i = 0; i < array.length; i++) {
                let arr2 = array[i]
                let arr3 = arr2.split('=')
                obj[arr3[0]] = arr3[1]
            }
            return obj

        },
        checkData(newObj,oldObj){
            let data={};
            for(let key in newObj){
                let d=newObj[key];
                let isOk=true;
                if(oldObj){
                    let d_=oldObj[key];
                    if(d==d_)
                        isOk=false;
                }
                 if((","+this.saveList+",").indexOf(","+key+",")!=-1){//必保存字段
                    isOk=true;
                    
                }
                if(isOk){
                    console.log("key====="+key+"=="+this.saveList)
                    data[key]=d;
                }
               
            }
            let isEmpty=true;
            for(let key in data){
                isEmpty=false;
            }
            if(!isEmpty){
                data[newObj.key_field]=newObj[newObj.key_field];
            }
            return data;
        },
        checkDataOld(newObj,oldObj){
            let data={};
            for(let key in newObj){
                let d=newObj[key];
                let isOk=true;
                let d_="";
                if(oldObj){
                    d_=oldObj[key];
                    if(d==d_)
                        isOk=false;
                }
               
                
                if((","+this.saveList+",").indexOf(","+key+",")!=-1){//必保存字段
                    isOk=true;
                   
                }
                if(isOk){
                    data[key]=d_;
                }
            }
            let isEmpty=true;
            for(let key in data){
                isEmpty=false;
            }
            if(!isEmpty){
                data[newObj.key_field]=newObj[newObj.key_field];
            }
            return data;
        },
        printss(printKey,params){
            let printKeys=printKey.split("#");

            let key=printKeys[1].split(".");
            let vals="";
            if(key.length>1){
                vals=this.data[key[0]][key[1]];
            }else if(key[0]=="ids"){
                vals=this.ids;
            }else
                vals=this.data[key[0]]

            
            
                
            let names=printKeys[0].split("|");
            let isPrint=names.length>1 ? names[1]:"";
            let items={};
            let name_=names[0];
            name_=name_.replace("打印","");
            items.buttonName="打印"+name_;
            items.text="打印"+name_;
            
            items.url="/commonPrint?printName="+name_+"&printId="+this.data.printId+"&sCurItem="+vals+"&token="+sessionStorage.getItem("token")+"&appid="+this.appid+"&isPrint="+isPrint;
            // alert(items.url)
            // parent.postMessage(JSON.stringify(items),'*');
            let printData_={};
            printData_.printName=name_;
            printData_.sCurItem=vals;
            printData_.printId=this.data.printId;
            printData_.appid=this.appid;
            printData_.token=sessionStorage.getItem("token");
            printData_.isPrint=isPrint;
            printData_.params=params;
            if(isPrint=="Y"){
                this.isPrint="Y";
            }else if(isPrint=="A"){
                this.isPrint="A";
            }else{
                this.isPrint="N";
                this.innerVisible=true;
                    //this.$emit("openWin",JSON.stringify(items))
            }
            
            this.printData=printData_;
                    
        },
        checkPrint(item){
            if(item.printKey){
                let printKey=item.printKey.split("#");

                console.log(item,"checkPrint===========")
                console.log(this.data)
                let sId=this.sId;
                if(printKey.length>1){
                    let ids=printKey[1].split(".");
                    if(ids.length==2){
                        sId=this.data[ids[0]][ids[1]]
                    }
                }
                
                let printName=printKey[0].split("|")[0]

                let printData_={};
                printData_.printName=printName;
                printData_.sCurItem=sId;
                printData_.appid="";
                printData_.token=sessionStorage.getItem("token");
                printData_.isPrint=printKey[0].split("|").length>1 ? printKey[0].split("|")[1]:"N";
                let isPrint=printKey[0].split("|").length>1 ? printKey[0].split("|")[1]:"N"

                let params={};

                for(let key in this.saveIds){
                    params[key]=this.saveIds[key];
                }
                printData_.params=params;

                if(isPrint=="Y"){
                    this.isPrint="Y";
                }else if(isPrint=="A"){
                    this.isPrint="A";
                }else{
                    this.isPrint="N";
                    this.innerVisible=true;
                        //this.$emit("openWin",JSON.stringify(items))
                }
                this.printData=printData_;
                return true;
            }else{
                return false;
            }
        },
        save(item,resolve){

            this.loading=true;
            //return;
            /*let forms=this.$refs.myForms;
            let isOk=true;
            for(let i=0;i<forms.length;i++){
                let message=forms[i].validate();
                if(message){
                    this.$message.error(message);
                    isOk=false;
                    this.loading=false;
                    break;
                }
               
            }*/
            
           
            let isOk=true;
            let formss=this.$refs.myFormss;
            for(let i=0;i<formss.length;i++){
                let message=formss[i].getValidateMsg();
                if(message){
                    this.$message.error(message);
                    isOk=false;
                    this.loading=false;
                    break;
                }
            }
            
            if(!isOk){
                this.loading=false;
            }
            
            if(isOk){
                //tableEidt组件需要重组数据
               /* try{    
                    let tableEdits=this.$refs.tableEdits
                    for(let i=0;i<tableEdits.length;i++){
                        try{
                            tableEdits[i].initSaveData();
                        }catch(e){}
                    }
                }catch(e){}*/
                try{
                    let el=this.$refs.myFormss;
                    for(let i=0;i<el.length;i++){
                        try{
                            el[i].initSaveData();
                        }catch(e){}
                        
                    }
                }catch(e){}

                let data_={};
                let dataold_={};
                let datadel_={};
                let  isCover="N";
                console.log("oldData==============================");
                console.log(this.data)
                console.log(this.oldData)
                if(this.sId){
                    isCover="Y";
                    for(let key in this.data){
                        let d=this.data[key];
                        let d_=this.oldData[key];
                        if(Array.isArray(d)){
                            let datas=[];
                            let datasold=[];
                            let datasdel=[];
                            for(let i=0;i<d.length;i++){
                                let da=d[i];
                                let da_=null;
                                let id=da[da.key_field];
                               // console.log("id======================="+id);
                               // console.log(da);
                               if(d_){
                                   for(let j=0;j<d_.length;j++){
                                        let da__=d_[j];
                                        
                                        if(id==da__[da__["key_field"]])
                                            da_=da__;
                                    }
                               }
                                
                                let data__=this.checkData(da,da_);
                                let dataold__=this.checkDataOld(da,da_);
                                let isEmpty=true;
                                for(let key_ in data__){
                                    isEmpty=false;
                                }
                                if(!isEmpty){
                                    datas.push(data__);
                                    datasold.push(dataold__);
                                }
                            }
                            //判断哪些被删除了
                            if(d_){
                                for(let i=0;i<d_.length;i++){
                                    let da=d_[i];
                                    let isNotDel=false;
                                    let id=da[da.key_field];
                                    for(let j=0;j<d.length;j++){
                                        let da__=d[j];
                                        
                                        if(id==da__[da__["key_field"]])
                                            isNotDel=true;
                                    }
                                    if(!isNotDel){
                                        datasdel.push(da)
                                    }
                                }
                            }
                            

                            if(datas.length>0){
                                data_[key]=datas;
                                dataold_[key]=datasold;
                            }
                            if(datasdel.length>0){
                                datadel_[key]=datasdel;
                            }
                        }else{
                            let data__=this.checkData(d,d_);
                            let dataold__=this.checkDataOld(d,d_);
                            let isEmpty=true;
                            console.log("data_==============================");
                            console.log(data__)
                            for(let key_ in data__){
                                isEmpty=false;
                            }
                            if(!isEmpty){
                                data_[key]=data__;
                                dataold_[key]=dataold__;
                            }
                        }
                    }
                }else{
                    
                    isCover="Y";
                    data_=this.data;
                }
                let urls=item.url;
                let type=item.type;
                let urlss_=urls.split(",");

                urls=urlss_[0];
                let appid_=this.appid;
                if(urlss_[0].indexOf("appid")!=-1){
                    let urls_=urlss_[0].split("#");
                    urls=urls_[1];
                    appid_=urls_[0].replace("appid=","");
                }
                let tel="";
                let code="";
                if(this.data.tel){
                    tel=this.data.tel;
                }
                if(this.data.code){
                    code=this.data.code;
                }
                this.$post(appid_,urls,{data:JSON.stringify(this.data),dataNew:JSON.stringify(data_),isCover:isCover,dataOld:JSON.stringify(dataold_),dataDel:JSON.stringify(datadel_),filename2:escape(this.filename),tel:tel,code:code,sId:this.sId,ids:this.ids}).then(data=>{
                     let isPost=false;
                     let status=data[0].status;
                     let msg=data[0].msg;
                     if(data[0].status=="+OK"){
                         this.saveIds=data[0].ids
                        this.GLOBAL.mark[this.mark]="Y";//保存后刷新主界面
                        try{
                            if(data[0].sId)
                                this.sId=data[0].sId;
                            if(urlss_.length<=1){
                                
                                if(this.data.sId!=this.sId){
                                    if(this.data.sId==undefined){
                                        this.loadDatas(true);
                                    }
                                    this.data.sId=this.sId;
                                }else{
                                    this.loadDatas(true);
                                    
                                }
                                //this.saveCallBack(item,this.saveIds) 
                                let isPrints=this.checkPrint(item)
                                if(isPrints){
                                    item.isAlert="N"
                                }
                            }
                            
                        }catch(e){}
                       
                        let data_={};
                        data_.type="goSearch";
                        data_.url=this.href;
                        if(this.commonEditData){
                            data_.searchType="dialog";
                        }
                        data_.isSearch=this.isSearch;
                        //parent.postMessage(JSON.stringify(data_),'*');
                        this.$emit("goSearch",JSON.stringify(data_))
                        if(this.data["imageList_"]){
                            
                            let id_=this.saveIds[this.data["imageList_"][0].key];
                           // alert(this.data["imageList_"][0].key+"=="+this.data["imageList_"][0].keyPid);
                            if(!id_){
                                id_=this.data[this.data["imageList_"][0].keyPid][this.data["imageList_"][0].key]
                            }
                            if(!id_){
                                id_=this.sId;
                            }
                            this.$post("business","/api/file/saveFile",{data:JSON.stringify(this.data["imageList_"]),id:id_}).then(data=>{

                            })
                        }
                        //有两个保存后台
                        if(urlss_.length>1){
                            for(let i=1;i<urlss_.length;i++){
                                let appid2_=this.appid;
                                if(urlss_[i].indexOf("appid")!=-1){
                                    let urls_=urlss_[i].split("#");
                                    urls=urls_[1];
                                    appid2_=urls_[0].replace("appid=","");
                                }
                                this.loadParam["sId"]=this.sId;
                                for(let key in this.saveIds){
                                    this.loadParam[key]=this.saveIds[key]
                                }
                                this.loadParam["data"]=JSON.stringify(this.data);
                                this.loadParam["dataNew"]=JSON.stringify(data_)
                                this.loadParam["dataOld"]=JSON.stringify(this.oldData)
                                isPost=true;
                                this.$post(appid2_,urls,this.loadParam).then(data=>{
                                    if(i+1==urlss_.length){
                                        
                                        this.checkPrint(item)
                                        let data_={};
                                        data_.type="goSearch";
                                        data_.url=this.href;
                                        if(this.commonEditData){
                                            data_.searchType="dialog";
                                        }
                                        data_.isSearch=this.isSearch;
                                        this.loading=false;
                                        //parent.postMessage(JSON.stringify(data_),'*');
                                        
                                        this.$emit("goSearch",JSON.stringify(data_))
                                        try{
                                            let status_="";
                                            let msg_="";
                                            try{
                                                status_=data.status;
                                                msg_=data.msg;
                                            }catch(e){}
                                            if(status_=="-ERR"){
                                                msg=msg_;
                                            }
                                            if(!msg_){
                                                msg_=msg;
                                            }
                                            this.loading=false;
                                            this.$alert(unescape(msg_), '提示', {
                                                confirmButtonText: '确定',
                                                callback: action => {
                                                    if(status_!="-ERR"){
                                                        //this.loadDatas(true);
                                                        console.log(JSON.stringify(this.data),"this.data===ss==")
                                                       // alert(this.data.sId+"=="+this.sId);
                                                        if(this.data.sId!=this.sId){
                                                            if(this.data.sId==undefined){
                                                                this.loadDatas(true);
                                                            }
                                                            this.data.sId=this.sId;
                                                        }else
                                                            this.loadDatas(true);
                                                        
                                                        //this.saveCallBack(item,this.saveIds) 
                                                        if(this.tabJson[0].isClose=="Y"){
                                                        /*  let data_={};
                                                            data_.type="close";
                                                            if(this.commonEditData){
                                                                data_.closeType="dialog";
                                                            }
                                                            this.$emit("closeWin",JSON.stringify(data_))*/
                                                            this.closeWin();
                                                            //parent.postMessage(JSON.stringify(data_),'*');
                                                        }
                                                    }
                                                }
                                            });
                            
                                        
                                            
                                        }catch(e){} 
                                    }
                                    
                                });
                            }
                            
                        }
                        if(type=="checkout"){
                            this.payId=this.saveIds.jz_id;
                           this.pays=true;
                        }
                    }else{
                        this.loading=false;
                    }
                   
                    if(!isPost&&item.isAlert!='N'){
                         this.$alert(unescape(data[0].msg), '提示', {
                            confirmButtonText: '确定',
                            callback: action => {
                               // this.loading=false;
                                if(data[0].status=='+OK'){
                                    if(this.tabJson[0].isClose=="Y"){
                                      /*  let data_={};
                                        data_.type="close";
                                        if(this.commonEditData){
                                            data_.closeType="dialog";
                                        }
                                        this.$emit("closeWin",JSON.stringify(data_))*/
                                         this.closeWin();
                                        //parent.postMessage(JSON.stringify(data_),'*');
                                    }
                                    
                                }
                            }
                        });
                        
                    }
                   
                    
                    if(resolve){
                        resolve("ok");
                    }
                }).catch(err=>{
                    console.log("err==============")
                    console.log(err);
                    this.loading=false;
                    this.$alert("报错出错:"+err.message, '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            
                        }
                    });
                });
            }
            
            
        },
        saveCallBack(item,params){
            let printKey=item.printKey;
            if(printKey){
                this.printss(printKey,params);
            }
            
        },
        closeWin(){
            if(this.isReturn=="Y"){
                this.returns();
            }else{
                let item_={};
                item_.type="close";
                if(this.commonEditData){
                    item_.closeType="dialog";
                }
                
                this.$emit("closeWin",JSON.stringify(item_));
                
            }
           
        },
        saveCommonData(data){//主要用于编辑界面里有列表，列表打开又编辑数据，而且是多条，没有保存后台所以要从tabMain页面把最里面的编辑界面的值传到指定组件，然后保存到json中
           let forms= this.$refs.myFormss;
           for(let i=0;i<forms.length;i++){
               forms[i].saveCommonData(data)
           }
        },
        saveData(){
            /*let forms=this.$refs.myForms;
            let isOk=true;
            try{
                for(let i=0;i<forms.length;i++){
                    let message=forms[i].validate();
                    if(message){
                        this.$message.error(message);
                        isOk=false;
                        this.loading=false;
                        break;
                    }
                
                }
            }catch(e){}*/
            let isOk=true;
            let formss=this.$refs.myFormss;
            for(let i=0;i<formss.length;i++){
                let message=formss[i].getValidateMsg();
                if(message){
                    this.$message.error(message);
                    isOk=false;
                    this.loading=false;
                    break;
                }
            }
            if(!isOk){
                this.loading=false;
            }
            

            let json={};
            json.isOk=isOk;
            if(isOk){

                let data_={};
                let dataold_={};
                let  isCover="N";
                if(this.sId){
                    isCover="Y";
                    for(let key in this.data){
                        let d=this.data[key];
                        let d_=this.oldData[key];
                        
                        if(Array.isArray(d)){
                            let datas=[];
                            let datasold=[];
                            for(let i=0;i<d.length;i++){
                                let da=d[i];
                                let da_=null;
                                let id=da.key_field;
                                
                               // console.log("id======================="+id);
                               // console.log(da);
                               if(d_){
                                   for(let j=0;j<d_.length;j++){
                                        let da__=d_[j];
                                        
                                        if(id==da__["key_field"])
                                            da_=da__;
                                    }
                               }
                                
                                let data__=this.checkData(da,da_);
                                let dataold__=this.checkDataOld(da,da_);
                                let isEmpty=true;
                                for(let key_ in data__){
                                    isEmpty=false;
                                }
                                if(!isEmpty){
                                    datas.push(data__);
                                    datasold.push(dataold__);
                                }
                            }
                            if(datas.length>0){
                                data_[key]=datas;
                                dataold_[key]=datasold;
                            }
                        }else{
                            let data__=this.checkData(d,d_);
                            let dataold__=this.checkDataOld(d,d_);
                            let isEmpty=true;
                            for(let key_ in data__){
                                isEmpty=false;
                            }
                            if(!isEmpty){
                                data_[key]=data__;
                                dataold_[key]=dataold__;
                            }
                        }
                    }
                }else{
                    
                    isCover="Y";
                    data_=this.data;
                }
               
                let appid_=this.appid;
               
                let tel="";
                let code="";
                if(this.data.tel){
                    tel=this.data.tel;
                }
                if(this.data.code){
                    code=this.data.code;
                }
                json.appid=appid_;
                json.data=this.data;
                json.dataNew=data_;
                json.isCover=isCover;
                json.dataOld=dataold_;
                json.tel=tel;
                json.code=code;

            }
          
            try{
               
                if(this.data["imageList_"]){
                     let keyPid=this.data["imageList_"][0].keyPid;
                    let key=this.data["imageList_"][0].key;
                    let id_=this.data[keyPid][key];
                    this.$post("business","/api/file/saveFile",{data:JSON.stringify(this.data["imageList_"]),id:id_}).then(data=>{

                    })
                }
            }catch(e){}
            return json;
        },
        goSearch(data){
            this.sId=data;
            this.loadDatas(true);
            this.tabs=this.tabJson[0].tabName;
        },
        goSeach2(){
            this.loadDatas(false);
        },
        openWin(data){
            this.$emit("openWin",data)
        },
        signClose(){
            this.signDialog=false;
            this.signDialogsd=false;
        },
        payClose(){
            this.pays=false;
        }
        
    }
}
</script>
<style scoped>
    
    .commonEdit{
       display:flex;
       box-sizing: border-box;
       -moz-box-sizing: border-box;
       -webkit-box-sizing: border-box;
       flex:1;
       border-radius: 5px;
       flex-direction: column;
       position: relative;
       overflow:hidden;
       height:100%;
       flex-direction:column;
       background:#efefef;
       padding:10px;
    }
    .commonEdit_content{
        flex:1;
        overflow:auto;
        display:flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
        align-content: flex-start;
    }
    .el-tabs{
        width:100%;
        flex:1;
        overflow:hidden;
        /*margin:10px;*/
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }
    .el-tabs__content{
        height:100%;
       /* overflow: auto;*/
        padding-bottom:10px !important;
    }
    .tabsMore{
        overflow-y:auto;
        overflow-x:hidden;
    }
    .tabOne{
        overflow:hidden;
    }
    .boxs{
        height:100%;
        text-align: center;
       display:flex;
        display: -webkit-flex;
        justify-content: center;
        height:100%;
    }
    .boxs2{
        height:100%;
       
        flex-direction: row;
        flex-wrap: wrap;
        align-items:flex-start;
        align-content:flex-start;
    }
    .boxs3{
        flex-direction: column;
        align-items:center;
        overflow: hidden;
    }
    .maxHeights{
        height:100%;
        overflow:hidden;
    }
    .cards{
        display:inline-block;
        /*float:left;*/
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        margin-bottom:5px;
       /* margin-left:2px;*/
    }
    .el-card__body{
         box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        padding-bottom: 30px;;
    }
    .btns{
        width:100%;
        height:50px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;

    }
    .btns_wrap{
        height:100%;
        width:100%;
        background:#f6f3f3;
        text-align: center;
        padding-top:0px;
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
    }
    .btns_wrap2{
        /*text-align: right;*/
    }
    input{
        height:25px;
    }
    .el-input__inner{
        height:25px;
    }
    .el-card__header{
        padding:10px 18px;
        border-bottom:1px solid blue;
    }
    .el-card{
        margin-top:5px;
        
    }
    .el-card>>>.clearfix{
        color:#66b1ff;
    }
    

  /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  ::-webkit-scrollbar{
    width: 12px;
    height: 12px;
    background-color: #F5F5F5;
  }

  /*定义滚动条轨道 内阴影+圆角*/
  ::-webkit-scrollbar-track {
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    background-color: #F5F5F5;
  }

  /*定义滑块 内阴影+圆角*/
  ::-webkit-scrollbar-thumb{
    border-radius: 10px;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);
    background-color: #c8c8c8;
  }

  .el-input__inner{
      font-family: 微软雅黑;
  }
  .button_item{
      display:inline-block;
      margin-left:6px;
  }
  .child_forms{
      flex-direction: row !important;
  }
  .btns2{
    text-align:center;
  }
  /*
  .signDialog>>>.el-dialog{
          display: flex;
          flex-direction: column;
          margin:0;
          position:absolute;
          top:0%;
          left:0%;
          transform:translate(-50%,-50%);
      }
    
   .signDialog>>>.el-dialog .el-dialog__body{
          flex:1;
          overflow: auto;
      }

      .signDialogsd>>>.el-dialog{
          display: flex;
          flex-direction: column;
          margin:0;
          position:absolute;
          top:0%;
          left:0%;
          /*transform:translate(-50%,-50%);
      }
    
   .signDialogsd>>>.el-dialog .el-dialog__body{
          flex:1;
          overflow: auto;
      }
      */
      /*
      .pays>>>.el-dialog{
          display: flex;
          flex-direction: column;
          margin:0;
          position:absolute;
          top:0%;
          left:0%;
          transform:translate(-50%,-50%);
      }
    
   .pays>>>.el-dialog .el-dialog__body{
          flex:1;
          overflow: auto;
      }*/
    .commonList_title_ytj{
        text-align: center;
        font-size:22px;
        height:50px;
        line-height: 50px;
    }
    .commonList_title{
        height:50px;
        border:1px solid #2294f2;
        padding-left:15px;
        border-bottom:0;
        line-height:35px;
        background:#2294f2;
        color:#fff;
    }
    .commonList_title i{
        margin-right:5px;
    }
    .el-tabs__item.is-active{
        background-color: rgb(4, 111, 193) !important;
    }

    .el-tabs--border-card>.el-tabs__header .el-tabs__item.is-active{
        
        background-color: rgb(4, 111, 193) !important;
    }
</style>
<style >
    .el-tabs__item.is-active{
        background-color: rgb(4, 111, 193) !important;
    }
    .el-card__body{
        flex:1;
        overflow-y:auto;
        overflow-x:hidden;
        padding-bottom:30px ;
    }
    .el-tabs__header{
      height:39px;
  }
  .el-card{
      display:flex;
      flex-direction: column;
  }
  .el-tabs__content{
      padding:0 !important;
  }
  
    
  .el-dialog__wrapper {
        text-align: center;
        white-space: nowrap;
        overflow: auto;
        width:100% !important;
        
    }
    .el-dialog__wrapper::after{
        content: "";
        display: inline-block;
        vertical-align: middle;
        height: 100%;
    }
   .el-dialog{
        margin: auto auto !important;
        display: inline-block;
        vertical-align: middle;
        text-align: center;
        white-space: normal;
        left:0% !important;
        top:0 !important
    }
</style>